Hi All |
Re: Match and Regular Expressions {code] Regexp re = regexp2(".*(Not K90)|(K90)") void Test(string s) { if (re s) // then print "yes\t[" s[match 1] "]\t[" s[match 2] "]\t*" s "*\n" else print "no \t*" s "*\n" } Test("yyy K90yyy") Test("yyy Not K90") Test("yyy NotK90") {code} prints this: yes [] [K90] *yyy K90yyy* yes [Not K90] [] *yyy Not K90* yes [] [K90] *yyy NotK90* So you could perhaps check for some kind of match, and when you find one figure out if its a match for [match 1] or [match 2], and go from there.
|
Re: Match and Regular Expressions
As Louie said, using two matches and then checking them before counting is probably the best solution. Since regexp does not support lookahead, you can only specify very awkward regular expressions that will count K90 but not count NOT K90. Its possible but awkward.
Regexp re = regexp "([^Tt ] *K90)|([^Oo][tT] ?K90)|([^Nn][oO][tT ] *K90)"
void Test(string s)
{
if (re s)
print "yes\t[" s "]\n"
else
print "no \t*" s "*\n"
// for i in 0:3 do print s[match i] "\n"
}
Test("yyy K90yyy")
Test("yyy Not K90")
Test("yyy NotK90")
Test("yyyNotK90")
Test("yyyNot yK90")
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Match and Regular Expressions Mathias Mamsch - Tue Jun 15 17:44:54 EDT 2010
As Louie said, using two matches and then checking them before counting is probably the best solution. Since regexp does not support lookahead, you can only specify very awkward regular expressions that will count K90 but not count NOT K90. Its possible but awkward.
Regexp re = regexp "([^Tt ] *K90)|([^Oo][tT] ?K90)|([^Nn][oO][tT ] *K90)"
void Test(string s)
{
if (re s)
print "yes\t[" s "]\n"
else
print "no \t*" s "*\n"
// for i in 0:3 do print s[match i] "\n"
}
Test("yyy K90yyy")
Test("yyy Not K90")
Test("yyy NotK90")
Test("yyyNotK90")
Test("yyyNot yK90")
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thank you so much for your responses. I believe that you have found a workable solution for me. Thanks again. |
Re: Match and Regular Expressions Mathias Mamsch - Tue Jun 15 17:44:54 EDT 2010
As Louie said, using two matches and then checking them before counting is probably the best solution. Since regexp does not support lookahead, you can only specify very awkward regular expressions that will count K90 but not count NOT K90. Its possible but awkward.
Regexp re = regexp "([^Tt ] *K90)|([^Oo][tT] ?K90)|([^Nn][oO][tT ] *K90)"
void Test(string s)
{
if (re s)
print "yes\t[" s "]\n"
else
print "no \t*" s "*\n"
// for i in 0:3 do print s[match i] "\n"
}
Test("yyy K90yyy")
Test("yyy Not K90")
Test("yyy NotK90")
Test("yyyNotK90")
Test("yyyNot yK90")
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
i have one string "s_Projectname" by value "ProductHMINavServerLib" and another list of strings which i had put into a skip "sk" those are 1. AICFHMINavServerLibRM 2. AICFHMINavServerLibPM 3. AICFHMINavServerLibSM 4. AICFHMINavServerLibFO 5. AICFHMINavServerLibST so what i am doing is for s_name in sk do { if(matches("."s_Projectname".", s_name) { print s_name"\n" } } as i am not able to match the strings using pattern matching in dxl. actually the project name is not intialized in the code,it is the project name which i am getting it from GUI,so the project name and the values in the skip will be varying , the above what i have mentioned is just an example if there are strings like that how can we macth it. kindly do the need full. if not possible kindly reply back. Thank you! regards, Shruthi |
Re: Match and Regular Expressions Bosch - Fri Jul 22 05:46:28 EDT 2011
You could search for the project name simply by using findPlaintext or just build a regular expression from your projectName e.g.
// make sure there are no special characters in your project name if you use regexp
Regexp rePrj = regexp "(.*)" sProjectName "(.*)"
for s_name in sk do {
if(rePrj s_name) {
print "Match: " s_name "\n"
string sPrefix = s_name[match 1]
string sPostfix = s_name[match 2]
print "Prefix: " sPrefix " Postfix:" sPostfix "\n"
}
}
delete rePrj // only in DOORS 9.1+
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Match and Regular Expressions Mathias Mamsch - Fri Jul 22 06:47:07 EDT 2011
You could search for the project name simply by using findPlaintext or just build a regular expression from your projectName e.g.
// make sure there are no special characters in your project name if you use regexp
Regexp rePrj = regexp "(.*)" sProjectName "(.*)"
for s_name in sk do {
if(rePrj s_name) {
print "Match: " s_name "\n"
string sPrefix = s_name[match 1]
string sPostfix = s_name[match 2]
print "Prefix: " sPrefix " Postfix:" sPostfix "\n"
}
}
delete rePrj // only in DOORS 9.1+
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks for your quick response! i have tried with the same string which i had mentioned in the above its not printing only. its not even entering into the loop. kindly help me.. Thank you! Regards, Shruthi |
Re: Match and Regular Expressions Mathias Mamsch - Fri Jul 22 06:47:07 EDT 2011
You could search for the project name simply by using findPlaintext or just build a regular expression from your projectName e.g.
// make sure there are no special characters in your project name if you use regexp
Regexp rePrj = regexp "(.*)" sProjectName "(.*)"
for s_name in sk do {
if(rePrj s_name) {
print "Match: " s_name "\n"
string sPrefix = s_name[match 1]
string sPostfix = s_name[match 2]
print "Prefix: " sPrefix " Postfix:" sPostfix "\n"
}
}
delete rePrj // only in DOORS 9.1+
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
This complete code works:
// make sure there are no special characters in your project name if you use regexp
string sProjectName = "MyProject"
string sLongName = "Prefix-" sProjectName "-Suffix"
string s_name
Skip skp = createString()
put(skp, sLongName, sLongName) // includes prefix and suffix
put(skp, sProjectName, sProjectName) // exact name
Regexp rePrj = regexp "(.*)" sProjectName "(.*)"
for s_name in skp do {
if(rePrj s_name) {
print "Match: Found [" sProjectName "] in string [" s_name "]\n"
string sPrefix = s_name[match 1]
string sPostfix = s_name[match 2]
print "Prefix: [" sPrefix "] Postfix:[" sPostfix "]\n"
}
}
delete rePrj // only in DOORS 9.1+
HA! Nice to know someone could make the same mistake I did! Of course, you have a good excuse, English being the 2nd language.
|
Re: Match and Regular Expressions llandale - Fri Jul 22 14:38:39 EDT 2011 This complete code works:
// make sure there are no special characters in your project name if you use regexp
string sProjectName = "MyProject"
string sLongName = "Prefix-" sProjectName "-Suffix"
string s_name
Skip skp = createString()
put(skp, sLongName, sLongName) // includes prefix and suffix
put(skp, sProjectName, sProjectName) // exact name
Regexp rePrj = regexp "(.*)" sProjectName "(.*)"
for s_name in skp do {
if(rePrj s_name) {
print "Match: Found [" sProjectName "] in string [" s_name "]\n"
string sPrefix = s_name[match 1]
string sPostfix = s_name[match 2]
print "Prefix: [" sPrefix "] Postfix:[" sPostfix "]\n"
}
}
delete rePrj // only in DOORS 9.1+
HA! Nice to know someone could make the same mistake I did! Of course, you have a good excuse, English being the 2nd language.
|
Re: Match and Regular Expressions Mathias Mamsch - Tue Jul 26 05:43:18 EDT 2011 May i know how to match multiple lines in a log file. Attached is the log file from where i have to get the text between two tags #IssueStart# and #IssueEnd#. Kindly help me out how to get the multiple lines. Thank you! Regards, Shruthi Attachments attachment_14691584_JIRA_TO_DOORS_Info.txt |
Re: Match and Regular Expressions Bosch - Tue Oct 11 02:29:12 EDT 2011 This is not a regular expression problem. Seems to me you want to read each line in the file, then check the characteristics of that line, and take appropriate action. Here is some psuedo code
Stream in = read(file)
Buffer bufIssue = create()
bool IssueMode = false
string Line, NameProject = "", NameFilter = ""
while (not end of stream)
{ in >> Line // read the next line
if (Line == "#IssueEnd#")
{ IssueMode = false
print "===Issue Block ===\n" tempStringOf(bufIssue) "\n=== End Block ===\n"
bufIssue = ""
}
elseif (IssueMode) bufIssue += Line "\n"
elseif (Line == "#IssueStart#") IssueMode = true
elseif (Line[0:10] == "ProjectName") NameProject = Line[12:]
elseif (Line[0: 5] == "Filter" NameFilter = Line[7:]
else {} //poorly formed line
}
close(in)
delete(bufIssue)
if (IssueMode) print "Poorly formed file, not end-of-block command '#IssueEnd#'\n"
print "NameProject:\t" NameProject\nNameFilter \t" NameFilter "\n"
|
Re: Match and Regular Expressions llandale - Tue Oct 11 10:33:46 EDT 2011 This is not a regular expression problem. Seems to me you want to read each line in the file, then check the characteristics of that line, and take appropriate action. Here is some psuedo code
Stream in = read(file)
Buffer bufIssue = create()
bool IssueMode = false
string Line, NameProject = "", NameFilter = ""
while (not end of stream)
{ in >> Line // read the next line
if (Line == "#IssueEnd#")
{ IssueMode = false
print "===Issue Block ===\n" tempStringOf(bufIssue) "\n=== End Block ===\n"
bufIssue = ""
}
elseif (IssueMode) bufIssue += Line "\n"
elseif (Line == "#IssueStart#") IssueMode = true
elseif (Line[0:10] == "ProjectName") NameProject = Line[12:]
elseif (Line[0: 5] == "Filter" NameFilter = Line[7:]
else {} //poorly formed line
}
close(in)
delete(bufIssue)
if (IssueMode) print "Poorly formed file, not end-of-block command '#IssueEnd#'\n"
print "NameProject:\t" NameProject\nNameFilter \t" NameFilter "\n"
similarly may i know how to read each line within issue block and end block,like i want to get the DOORSID,object heading ,object text, and JIRAURL with respective data. Thank you! Regards, Shruthi |
Re: Match and Regular Expressions Bosch - Wed Oct 12 00:28:16 EDT 2011 Someone will surely jump in here with an elegant Regular Expression solution, but...
string StripStartEnd(string in_Line)
{ string Result = in_Line
if (Result[0:6] == "#Start#") Result = Result[7:]
int len = length(Result)
if (Result[len-5:] == "#End#) Result = Result[0:len-6]
return(Result)
}
void ProcessIssueLine(string in_Line, &out_DoorsID, &out_Heading, &out_Text, &out_Jirautl)
{
if (in_Line[0: 7] == "DOORSID=") out_DoorsID = In_Line[8:]
elseif(in_Line[0:14] == "Object Heading=") out_Heading = StripStartEnd(in_Line[15:])
elseif(in_Line[0:11] == "Object Text=") out_Text = StripStartEnd(in_Line[12:])
elseif(in_Line[0: 7] == "JIRAURL=") out_Jiraurl = InLine[8:]
}
|